from typing import List
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from mooc.api import deps
from mooc.crud.crud_uni_account import (
    uni_account, uni_account_extra_modules, 
    uni_account_group, uni_account_menus, 
    uni_account_modules, uni_account_modules_shortcut, 
    uni_account_users, uni_group, 
    uni_link_uniacid, uni_modules, 
    uni_verifycode, uni_settings
)
from mooc.schemas.uni_account import (
    UniAccountCreate,
    UniAccountRead,
    UniAccountUpdate,
    UniAccountExtraModulesCreate,
    UniAccountExtraModulesRead,
    UniAccountExtraModulesUpdate,
    UniAccountGroupCreate,
    UniAccountGroupRead,
    UniAccountGroupUpdate,
    UniAccountMenusCreate,
    UniAccountMenusRead,
    UniAccountMenusUpdate,
    UniAccountModulesCreate,
    UniAccountModulesRead,
    UniAccountModulesUpdate,
    UniAccountModulesShortcutCreate,
    UniAccountModulesShortcutRead,
    UniAccountModulesShortcutUpdate,
    UniAccountUsersCreate,
    UniAccountUsersRead,
    UniAccountUsersUpdate,
    UniGroupCreate,
    UniGroupRead,
    UniGroupUpdate,
    UniLinkUniacidCreate,
    UniLinkUniacidRead,
    UniLinkUniacidUpdate,
    UniModulesCreate,
    UniModulesRead,
    UniModulesUpdate,
    UniVerifycodeCreate,
    UniVerifycodeRead,
    UniVerifycodeUpdate,
    UniSettingsCreate,
    UniSettingsRead,
    UniSettingsUpdate
)

uni_account_router = APIRouter()

# UniAccount 路由
@uni_account_router.post("/", response_model=UniAccountRead)
def create_uni_account(
    *,
    db: Session = Depends(deps.get_db),
    uni_account_in: UniAccountCreate,
):
    """
    创建统一公众号账户
    """
    return uni_account.create(db=db, obj_in=uni_account_in)

@uni_account_router.get("/{uniacid}", response_model=UniAccountRead)
def read_uni_account(
    *,
    db: Session = Depends(deps.get_db),
    uniacid: int,
):
    """
    获取统一公众号账户信息
    """
    db_uni_account = uni_account.get(db=db, id=uniacid)
    if not db_uni_account:
        raise HTTPException(
            status_code=404,
            detail="UniAccount not found"
        )
    return db_uni_account

@uni_account_router.put("/{uniacid}", response_model=UniAccountRead)
def update_uni_account(
    *,
    db: Session = Depends(deps.get_db),
    uniacid: int,
    uni_account_in: UniAccountUpdate,
):
    """
    更新统一公众号账户信息
    """
    db_uni_account = uni_account.get(db=db, id=uniacid)
    if not db_uni_account:
        raise HTTPException(
            status_code=404,
            detail="UniAccount not found"
        )
    return uni_account.update(db=db, db_obj=db_uni_account, obj_in=uni_account_in)

@uni_account_router.delete("/{uniacid}", response_model=UniAccountRead)
def delete_uni_account(
    *,
    db: Session = Depends(deps.get_db),
    uniacid: int,
):
    """
    删除统一公众号账户
    """
    db_uni_account = uni_account.get(db=db, id=uniacid)
    if not db_uni_account:
        raise HTTPException(
            status_code=404,
            detail="UniAccount not found"
        )
    return uni_account.delete(db=db, id=uniacid)

# UniAccountExtraModules 路由
@uni_account_router.post("/modules", response_model=UniAccountExtraModulesRead)
def create_extra_modules(
    *,
    db: Session = Depends(deps.get_db),
    modules_in: UniAccountExtraModulesCreate,
):
    """
    创建账户额外模块
    """
    return uni_account_extra_modules.create(db=db, obj_in=modules_in)

@uni_account_router.get("/modules/{id}", response_model=UniAccountExtraModulesRead)
def read_extra_modules(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
):
    """
    获取账户额外模块信息
    """
    db_modules = uni_account_extra_modules.get(db=db, id=id)
    if not db_modules:
        raise HTTPException(
            status_code=404,
            detail="Extra modules not found"
        )
    return db_modules

@uni_account_router.get("/modules/by-uniacid/{uniacid}", response_model=UniAccountExtraModulesRead)
def read_extra_modules_by_uniacid(
    *,
    db: Session = Depends(deps.get_db),
    uniacid: int,
):
    """
    通过uniacid获取账户额外模块信息
    """
    db_modules = uni_account_extra_modules.get_by_uniacid(db=db, uniacid=uniacid)
    if not db_modules:
        raise HTTPException(
            status_code=404,
            detail="Extra modules not found"
        )
    return db_modules

@uni_account_router.put("/modules/{id}", response_model=UniAccountExtraModulesRead)
def update_extra_modules(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    modules_in: UniAccountExtraModulesUpdate,
):
    """
    更新账户额外模块信息
    """
    db_modules = uni_account_extra_modules.get(db=db, id=id)
    if not db_modules:
        raise HTTPException(
            status_code=404,
            detail="Extra modules not found"
        )
    return uni_account_extra_modules.update(db=db, db_obj=db_modules, obj_in=modules_in)

@uni_account_router.delete("/modules/{id}", response_model=UniAccountExtraModulesRead)
def delete_extra_modules(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
):
    """
    删除账户额外模块
    """
    db_modules = uni_account_extra_modules.get(db=db, id=id)
    if not db_modules:
        raise HTTPException(
            status_code=404,
            detail="Extra modules not found"
        )
    return uni_account_extra_modules.delete(db=db, id=id)

# UniAccountGroup 路由
@uni_account_router.post("/groups", response_model=UniAccountGroupRead)
def create_group(
    *,
    db: Session = Depends(deps.get_db),
    group_in: UniAccountGroupCreate,
):
    """创建账户组关联"""
    return uni_account_group.create(db=db, obj_in=group_in)

@uni_account_router.get("/groups/{id}", response_model=UniAccountGroupRead)
def read_group(*, db: Session = Depends(deps.get_db), id: int):
    """获取账户组关联信息"""
    group = uni_account_group.get(db=db, id=id)
    if not group:
        raise HTTPException(status_code=404, detail="Account group not found")
    return group

@uni_account_router.put("/groups/{id}", response_model=UniAccountGroupRead)
def update_group(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    group_in: UniAccountGroupUpdate,
):
    """更新账户组关联信息"""
    group = uni_account_group.get(db=db, id=id)
    if not group:
        raise HTTPException(status_code=404, detail="Account group not found")
    return uni_account_group.update(db=db, db_obj=group, obj_in=group_in)

@uni_account_router.delete("/groups/{id}", response_model=UniAccountGroupRead)
def delete_group(*, db: Session = Depends(deps.get_db), id: int):
    """删除账户组关联"""
    group = uni_account_group.get(db=db, id=id)
    if not group:
        raise HTTPException(status_code=404, detail="Account group not found")
    return uni_account_group.delete(db=db, id=id)

# UniAccountMenus 路由
@uni_account_router.post("/menus", response_model=UniAccountMenusRead)
def create_menu(
    *,
    db: Session = Depends(deps.get_db),
    menu_in: UniAccountMenusCreate,
):
    """创建账户菜单"""
    return uni_account_menus.create(db=db, obj_in=menu_in)

@uni_account_router.get("/menus/{id}", response_model=UniAccountMenusRead)
def read_menu(*, db: Session = Depends(deps.get_db), id: int):
    """获取账户菜单信息"""
    menu = uni_account_menus.get(db=db, id=id)
    if not menu:
        raise HTTPException(status_code=404, detail="Account menu not found")
    return menu

@uni_account_router.get("/menus/by-uniacid/{uniacid}", response_model=UniAccountMenusRead)
def read_menu_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取账户菜单信息"""
    menu = uni_account_menus.get_by_uniacid(db=db, uniacid=uniacid)
    if not menu:
        raise HTTPException(status_code=404, detail="Account menu not found")
    return menu

@uni_account_router.put("/menus/{id}", response_model=UniAccountMenusRead)
def update_menu(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    menu_in: UniAccountMenusUpdate,
):
    """更新账户菜单信息"""
    menu = uni_account_menus.get(db=db, id=id)
    if not menu:
        raise HTTPException(status_code=404, detail="Account menu not found")
    return uni_account_menus.update(db=db, db_obj=menu, obj_in=menu_in)

@uni_account_router.delete("/menus/{id}", response_model=UniAccountMenusRead)
def delete_menu(*, db: Session = Depends(deps.get_db), id: int):
    """删除账户菜单"""
    menu = uni_account_menus.get(db=db, id=id)
    if not menu:
        raise HTTPException(status_code=404, detail="Account menu not found")
    return uni_account_menus.delete(db=db, id=id)

# UniAccountModules 路由
@uni_account_router.post("/modules", response_model=UniAccountModulesRead)
def create_module(
    *,
    db: Session = Depends(deps.get_db),
    module_in: UniAccountModulesCreate,
):
    """创建账户模块"""
    return uni_account_modules.create(db=db, obj_in=module_in)

@uni_account_router.get("/modules/{id}", response_model=UniAccountModulesRead)
def read_module(*, db: Session = Depends(deps.get_db), id: int):
    """获取账户模块信息"""
    module = uni_account_modules.get(db=db, id=id)
    if not module:
        raise HTTPException(status_code=404, detail="Account module not found")
    return module

@uni_account_router.get("/modules/by-uniacid/{uniacid}", response_model=UniAccountModulesRead)
def read_module_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取账户模块信息"""
    module = uni_account_modules.get_by_uniacid(db=db, uniacid=uniacid)
    if not module:
        raise HTTPException(status_code=404, detail="Account module not found")
    return module

@uni_account_router.put("/modules/{id}", response_model=UniAccountModulesRead)
def update_module(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    module_in: UniAccountModulesUpdate,
):
    """更新账户模块信息"""
    module = uni_account_modules.get(db=db, id=id)
    if not module:
        raise HTTPException(status_code=404, detail="Account module not found")
    return uni_account_modules.update(db=db, db_obj=module, obj_in=module_in)

@uni_account_router.delete("/modules/{id}", response_model=UniAccountModulesRead)
def delete_module(*, db: Session = Depends(deps.get_db), id: int):
    """删除账户模块"""
    module = uni_account_modules.get(db=db, id=id)
    if not module:
        raise HTTPException(status_code=404, detail="Account module not found")
    return uni_account_modules.delete(db=db, id=id)

# UniAccountModulesShortcut 完整路由
@uni_account_router.post("/modules-shortcut", response_model=UniAccountModulesShortcutRead)
def create_module_shortcut(
    *,
    db: Session = Depends(deps.get_db),
    shortcut_in: UniAccountModulesShortcutCreate,
):
    """创建模块快捷方式"""
    return uni_account_modules_shortcut.create(db=db, obj_in=shortcut_in)

@uni_account_router.get("/modules-shortcut/{id}", response_model=UniAccountModulesShortcutRead)
def read_module_shortcut(*, db: Session = Depends(deps.get_db), id: int):
    """获取模块快捷方式"""
    shortcut = uni_account_modules_shortcut.get(db=db, id=id)
    if not shortcut:
        raise HTTPException(status_code=404, detail="Module shortcut not found")
    return shortcut

@uni_account_router.get("/modules-shortcut/by-uniacid/{uniacid}", response_model=UniAccountModulesShortcutRead)
def read_module_shortcut_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取模块快捷方式"""
    shortcut = uni_account_modules_shortcut.get_by_uniacid(db=db, uniacid=uniacid)
    if not shortcut:
        raise HTTPException(status_code=404, detail="Module shortcut not found")
    return shortcut

@uni_account_router.put("/modules-shortcut/{id}", response_model=UniAccountModulesShortcutRead)
def update_module_shortcut(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    shortcut_in: UniAccountModulesShortcutUpdate,
):
    """更新模块快捷方式"""
    shortcut = uni_account_modules_shortcut.get(db=db, id=id)
    if not shortcut:
        raise HTTPException(status_code=404, detail="Module shortcut not found")
    return uni_account_modules_shortcut.update(db=db, db_obj=shortcut, obj_in=shortcut_in)

@uni_account_router.delete("/modules-shortcut/{id}", response_model=UniAccountModulesShortcutRead)
def delete_module_shortcut(*, db: Session = Depends(deps.get_db), id: int):
    """删除模块快捷方式"""
    shortcut = uni_account_modules_shortcut.get(db=db, id=id)
    if not shortcut:
        raise HTTPException(status_code=404, detail="Module shortcut not found")
    return uni_account_modules_shortcut.delete(db=db, id=id)

# UniAccountUsers 完整路由
@uni_account_router.post("/users", response_model=UniAccountUsersRead)
def create_account_user(
    *,
    db: Session = Depends(deps.get_db),
    user_in: UniAccountUsersCreate,
):
    """创建账户用户关联"""
    return uni_account_users.create(db=db, obj_in=user_in)

@uni_account_router.get("/users/{id}", response_model=UniAccountUsersRead)
def read_account_user(*, db: Session = Depends(deps.get_db), id: int):
    """获取账户用户关联信息"""
    user = uni_account_users.get(db=db, id=id)
    if not user:
        raise HTTPException(status_code=404, detail="Account user not found")
    return user

@uni_account_router.get("/users/by-uniacid/{uniacid}", response_model=UniAccountUsersRead)
def read_account_user_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取账户用户关联信息"""
    user = uni_account_users.get_by_uniacid(db=db, uniacid=uniacid)
    if not user:
        raise HTTPException(status_code=404, detail="Account user not found")
    return user

@uni_account_router.get("/users/by-uid/{uid}", response_model=UniAccountUsersRead)
def read_account_user_by_uid(*, db: Session = Depends(deps.get_db), uid: int):
    """通过uid获取账户用户关联信息"""
    user = uni_account_users.get_by_uid(db=db, uid=uid)
    if not user:
        raise HTTPException(status_code=404, detail="Account user not found")
    return user

@uni_account_router.put("/users/{id}", response_model=UniAccountUsersRead)
def update_account_user(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    user_in: UniAccountUsersUpdate,
):
    """更新账户用户关联信息"""
    user = uni_account_users.get(db=db, id=id)
    if not user:
        raise HTTPException(status_code=404, detail="Account user not found")
    return uni_account_users.update(db=db, db_obj=user, obj_in=user_in)

@uni_account_router.delete("/users/{id}", response_model=UniAccountUsersRead)
def delete_account_user(*, db: Session = Depends(deps.get_db), id: int):
    """删除账户用户关联"""
    user = uni_account_users.get(db=db, id=id)
    if not user:
        raise HTTPException(status_code=404, detail="Account user not found")
    return uni_account_users.delete(db=db, id=id)

# UniGroup 完整路由
@uni_account_router.post("/groups", response_model=UniGroupRead)
def create_uni_group(
    *,
    db: Session = Depends(deps.get_db),
    group_in: UniGroupCreate,
):
    """创建统一公众号组"""
    return uni_group.create(db=db, obj_in=group_in)

@uni_account_router.get("/groups/{id}", response_model=UniGroupRead)
def read_uni_group(*, db: Session = Depends(deps.get_db), id: int):
    """获取统一公众号组信息"""
    group = uni_group.get(db=db, id=id)
    if not group:
        raise HTTPException(status_code=404, detail="Uni group not found")
    return group

@uni_account_router.get("/groups/by-uniacid/{uniacid}", response_model=UniGroupRead)
def read_uni_group_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取统一公众号组信息"""
    group = uni_group.get_by_uniacid(db=db, uniacid=uniacid)
    if not group:
        raise HTTPException(status_code=404, detail="Uni group not found")
    return group

@uni_account_router.get("/groups/by-owner/{owner_uid}", response_model=UniGroupRead)
def read_uni_group_by_owner(*, db: Session = Depends(deps.get_db), owner_uid: int):
    """通过owner_uid获取统一公众号组信息"""
    group = uni_group.get_by_owner(db=db, owner_uid=owner_uid)
    if not group:
        raise HTTPException(status_code=404, detail="Uni group not found")
    return group

@uni_account_router.put("/groups/{id}", response_model=UniGroupRead)
def update_uni_group(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    group_in: UniGroupUpdate,
):
    """更新统一公众号组信息"""
    group = uni_group.get(db=db, id=id)
    if not group:
        raise HTTPException(status_code=404, detail="Uni group not found")
    return uni_group.update(db=db, db_obj=group, obj_in=group_in)

@uni_account_router.delete("/groups/{id}", response_model=UniGroupRead)
def delete_uni_group(*, db: Session = Depends(deps.get_db), id: int):
    """删除统一公众号组"""
    group = uni_group.get(db=db, id=id)
    if not group:
        raise HTTPException(status_code=404, detail="Uni group not found")
    return uni_group.delete(db=db, id=id)

# UniLinkUniacid 路由
@uni_account_router.post("/links", response_model=UniLinkUniacidRead)
def create_link_uniacid(
    *,
    db: Session = Depends(deps.get_db),
    link_in: UniLinkUniacidCreate,
):
    """创建公众号链接关系"""
    return uni_link_uniacid.create(db=db, obj_in=link_in)

@uni_account_router.get("/links/{id}", response_model=UniLinkUniacidRead)
def read_link_uniacid(*, db: Session = Depends(deps.get_db), id: int):
    """获取公众号链接关系"""
    link = uni_link_uniacid.get(db=db, id=id)
    if not link:
        raise HTTPException(status_code=404, detail="Link uniacid not found")
    return link

@uni_account_router.get("/links/by-uniacid/{uniacid}", response_model=UniLinkUniacidRead)
def read_link_uniacid_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取公众号链接关系"""
    link = uni_link_uniacid.get_by_uniacid(db=db, uniacid=uniacid)
    if not link:
        raise HTTPException(status_code=404, detail="Link uniacid not found")
    return link

@uni_account_router.put("/links/{id}", response_model=UniLinkUniacidRead)
def update_link_uniacid(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    link_in: UniLinkUniacidUpdate,
):
    """更新公众号链接关系"""
    link = uni_link_uniacid.get(db=db, id=id)
    if not link:
        raise HTTPException(status_code=404, detail="Link uniacid not found")
    return uni_link_uniacid.update(db=db, db_obj=link, obj_in=link_in)

@uni_account_router.delete("/links/{id}", response_model=UniLinkUniacidRead)
def delete_link_uniacid(*, db: Session = Depends(deps.get_db), id: int):
    """删除公众号链接关系"""
    link = uni_link_uniacid.get(db=db, id=id)
    if not link:
        raise HTTPException(status_code=404, detail="Link uniacid not found")
    return uni_link_uniacid.delete(db=db, id=id)

# UniModules 路由
@uni_account_router.post("/uni-modules", response_model=UniModulesRead)
def create_uni_module(
    *,
    db: Session = Depends(deps.get_db),
    module_in: UniModulesCreate,
):
    """创建统一模块"""
    return uni_modules.create(db=db, obj_in=module_in)

@uni_account_router.get("/uni-modules/{id}", response_model=UniModulesRead)
def read_uni_module(*, db: Session = Depends(deps.get_db), id: int):
    """获取统一模块信息"""
    module = uni_modules.get(db=db, id=id)
    if not module:
        raise HTTPException(status_code=404, detail="Uni module not found")
    return module

@uni_account_router.get("/uni-modules/by-uniacid/{uniacid}", response_model=UniModulesRead)
def read_uni_module_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取统一模块信息"""
    module = uni_modules.get_by_uniacid(db=db, uniacid=uniacid)
    if not module:
        raise HTTPException(status_code=404, detail="Uni module not found")
    return module

@uni_account_router.put("/uni-modules/{id}", response_model=UniModulesRead)
def update_uni_module(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    module_in: UniModulesUpdate,
):
    """更新统一模块信息"""
    module = uni_modules.get(db=db, id=id)
    if not module:
        raise HTTPException(status_code=404, detail="Uni module not found")
    return uni_modules.update(db=db, db_obj=module, obj_in=module_in)

@uni_account_router.delete("/uni-modules/{id}", response_model=UniModulesRead)
def delete_uni_module(*, db: Session = Depends(deps.get_db), id: int):
    """删除统一模块"""
    module = uni_modules.get(db=db, id=id)
    if not module:
        raise HTTPException(status_code=404, detail="Uni module not found")
    return uni_modules.delete(db=db, id=id)

# UniVerifycode 路由
@uni_account_router.post("/verifycodes", response_model=UniVerifycodeRead)
def create_verifycode(
    *,
    db: Session = Depends(deps.get_db),
    verifycode_in: UniVerifycodeCreate,
):
    """创建验证码"""
    return uni_verifycode.create(db=db, obj_in=verifycode_in)

@uni_account_router.get("/verifycodes/{id}", response_model=UniVerifycodeRead)
def read_verifycode(*, db: Session = Depends(deps.get_db), id: int):
    """获取验证码信息"""
    verifycode = uni_verifycode.get(db=db, id=id)
    if not verifycode:
        raise HTTPException(status_code=404, detail="Verifycode not found")
    return verifycode

@uni_account_router.get("/verifycodes/by-uniacid/{uniacid}", response_model=UniVerifycodeRead)
def read_verifycode_by_uniacid(*, db: Session = Depends(deps.get_db), uniacid: int):
    """通过uniacid获取验证码信息"""
    verifycode = uni_verifycode.get_by_uniacid(db=db, uniacid=uniacid)
    if not verifycode:
        raise HTTPException(status_code=404, detail="Verifycode not found")
    return verifycode

@uni_account_router.get("/verifycodes/by-receiver/{receiver}", response_model=UniVerifycodeRead)
def read_verifycode_by_receiver(*, db: Session = Depends(deps.get_db), receiver: str):
    """通过接收者获取验证码信息"""
    verifycode = uni_verifycode.get_by_receiver(db=db, receiver=receiver)
    if not verifycode:
        raise HTTPException(status_code=404, detail="Verifycode not found")
    return verifycode

@uni_account_router.put("/verifycodes/{id}", response_model=UniVerifycodeRead)
def update_verifycode(
    *,
    db: Session = Depends(deps.get_db),
    id: int,
    verifycode_in: UniVerifycodeUpdate,
):
    """更新验证码信息"""
    verifycode = uni_verifycode.get(db=db, id=id)
    if not verifycode:
        raise HTTPException(status_code=404, detail="Verifycode not found")
    return uni_verifycode.update(db=db, db_obj=verifycode, obj_in=verifycode_in)

@uni_account_router.delete("/verifycodes/{id}", response_model=UniVerifycodeRead)
def delete_verifycode(*, db: Session = Depends(deps.get_db), id: int):
    """删除验证码"""
    verifycode = uni_verifycode.get(db=db, id=id)
    if not verifycode:
        raise HTTPException(status_code=404, detail="Verifycode not found")
    return uni_verifycode.delete(db=db, id=id)

# UniSettings 路由
@uni_account_router.post("/settings", response_model=UniSettingsRead)
def create_settings(
    *,
    db: Session = Depends(deps.get_db),
    settings_in: UniSettingsCreate,
):
    """创建公众号设置"""
    # 检查是否已存在该uniacid的设置
    existing_settings = uni_settings.get_by_uniacid(db=db, uniacid=settings_in.uniacid)
    if existing_settings:
        raise HTTPException(
            status_code=400,
            detail="Settings for this uniacid already exists"
        )
    return uni_settings.create_with_uniacid(db=db, obj_in=settings_in)

@uni_account_router.get("/settings/{uniacid}", response_model=UniSettingsRead)
def read_settings(*, db: Session = Depends(deps.get_db), uniacid: int):
    """获取公众号设置"""
    settings = uni_settings.get_by_uniacid(db=db, uniacid=uniacid)
    if not settings:
        raise HTTPException(status_code=404, detail="Settings not found")
    return settings

@uni_account_router.put("/settings/{uniacid}", response_model=UniSettingsRead)
def update_settings(
    *,
    db: Session = Depends(deps.get_db),
    uniacid: int,
    settings_in: UniSettingsUpdate,
):
    """更新公众号设置"""
    settings = uni_settings.get_by_uniacid(db=db, uniacid=uniacid)
    if not settings:
        raise HTTPException(status_code=404, detail="Settings not found")
    return uni_settings.update(db=db, db_obj=settings, obj_in=settings_in)

@uni_account_router.delete("/settings/{uniacid}", response_model=UniSettingsRead)
def delete_settings(*, db: Session = Depends(deps.get_db), uniacid: int):
    """删除公众号设置"""
    settings = uni_settings.get_by_uniacid(db=db, uniacid=uniacid)
    if not settings:
        raise HTTPException(status_code=404, detail="Settings not found")
    return uni_settings.delete(db=db, id=uniacid) 